package br.com.async.core.domain.enterprise;

import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.SequenceGenerator;

import org.hibernate.annotations.IndexColumn;

import br.com.async.core.domain.AbstractBookmarks;
import br.com.async.core.domain.address.ComercialAddress;
import br.com.async.core.domain.bookmark.Evaluation;
import br.com.async.core.domain.person.Person;

@Entity(name = "tb_enterprise")
public class Enterprise implements AbstractBookmarks {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@SequenceGenerator(allocationSize = 1, initialValue = 1, name = "enterprise_code", sequenceName = "enterprise_code")
	@GeneratedValue(generator = "enterprise_code", strategy = GenerationType.AUTO)
	@JoinColumn(nullable = false)
	private Integer code;
	private String cnpj;
	@OneToOne(cascade = CascadeType.ALL)
	@JoinColumn(name = "person")
	private Person person;
	@OneToOne(cascade = CascadeType.ALL)
	private ComercialAddress comercialAddress;
	@OneToOne(cascade = CascadeType.ALL)
	private ProfileDetail profileDetail;
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.EAGER)
	@IndexColumn(name = "evaluation")
	private List<Evaluation> evaluation;
	private String url;
	private String description;

	public Enterprise() {

	}

	public Enterprise(String cnpj, Person person,
			ComercialAddress comercialAddress, ProfileDetail profileDetail,
			String url, String description) {
		super();
		this.cnpj = cnpj;
		this.person = person;
		this.comercialAddress = comercialAddress;
		this.profileDetail = profileDetail;
		this.url = url;
		this.description = description;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public String getCnpj() {
		return cnpj;
	}

	public void setCnpj(String cnpj) {
		this.cnpj = cnpj;
	}

	public Person getPerson() {
		return person;
	}

	public void setPerson(Person person) {
		this.person = person;
	}

	public ComercialAddress getComercialAddress() {
		return comercialAddress;
	}

	public void setComercialAddress(ComercialAddress comercialAddress) {
		this.comercialAddress = comercialAddress;
	}

	public ProfileDetail getProfileDetail() {
		return profileDetail;
	}

	public void setProfileDetail(ProfileDetail profileDetail) {
		this.profileDetail = profileDetail;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getUrl() {
		return url;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getDescription() {
		return description;
	}

	public List<Evaluation> getEvaluation() {
		return evaluation;
	}

	public void setEvaluation(List<Evaluation> evaluation) {
		this.evaluation = evaluation;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((cnpj == null) ? 0 : cnpj.hashCode());
		result = prime * result + ((code == null) ? 0 : code.hashCode());
		result = prime
				* result
				+ ((comercialAddress == null) ? 0 : comercialAddress.hashCode());
		result = prime * result
				+ ((description == null) ? 0 : description.hashCode());
		result = prime * result
				+ ((evaluation == null) ? 0 : evaluation.hashCode());
		result = prime * result + ((person == null) ? 0 : person.hashCode());
		result = prime * result
				+ ((profileDetail == null) ? 0 : profileDetail.hashCode());
		result = prime * result + ((url == null) ? 0 : url.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Enterprise other = (Enterprise) obj;
		if (cnpj == null) {
			if (other.cnpj != null)
				return false;
		} else if (!cnpj.equals(other.cnpj))
			return false;
		if (code == null) {
			if (other.code != null)
				return false;
		} else if (!code.equals(other.code))
			return false;
		if (comercialAddress == null) {
			if (other.comercialAddress != null)
				return false;
		} else if (!comercialAddress.equals(other.comercialAddress))
			return false;
		if (description == null) {
			if (other.description != null)
				return false;
		} else if (!description.equals(other.description))
			return false;
		if (evaluation == null) {
			if (other.evaluation != null)
				return false;
		} else if (!evaluation.equals(other.evaluation))
			return false;
		if (person == null) {
			if (other.person != null)
				return false;
		} else if (!person.equals(other.person))
			return false;
		if (profileDetail == null) {
			if (other.profileDetail != null)
				return false;
		} else if (!profileDetail.equals(other.profileDetail))
			return false;
		if (url == null) {
			if (other.url != null)
				return false;
		} else if (!url.equals(other.url))
			return false;
		return true;
	}

}
